Making plots is a very repetitive: draw this line, add these colored points, then add these, etc. Instead of re-using the same code over and over, ggplot implements them using a high-level but very expressive API. The result is less time spent creating your charts, and more time interpreting what they mean.
ggplot is not a good fit for people trying to make highly customized data visualizations. While you can make some very intricate, great looking plots, ggplot sacrifices highly customization in favor of general doing "what you'd expect".
In [1]:
%matplotlib inline
from ggplot import *
diamonds.head()
Out[1]:
Aesthetics describe how your data will relate to your plots. Some common aesthetics are: x
, y
, and color. Aesthetics are specific to the type of plot (or layer) you're adding to your visual. For example, a scatterplot (geom_point) and a line (geom_line) will share x
and y
, but only a line chart has a linetype
aesthetic.
In [2]:
aes(x='carat', y='price')
aes(x='price', fill='clarity')
aes(x='date', y='beef')
Out[2]:
In [3]:
p = ggplot(aes(x='date', y='beef'), data=meat)
p
Out[3]:
Add some points
In [17]:
p + geom_point()
Out[17]:
Add a line.
In [5]:
p + geom_point() + geom_line()
Out[5]:
Add a trendline
In [6]:
p + geom_point() + geom_line() + stat_smooth(color='blue')
Out[6]:
In [15]:
p + geom_point(color='black') + stat_smooth(method='ma', window=12, color='royalblue')
Out[15]:
In [ ]: